package com.purong.purong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.BankBean;
import com.purong.purong.widget.RadiusImageView;
import com.yao.sdk.glide.GlideUtil;

import java.util.List;


public class BankGridAdapter extends BaseAdapter {

    private Context mContext;
    private List<BankBean> mBankList;
    private OnBankClickListener mListener;
    @Override
    public int getCount() {
        return mBankList == null ? 0 : mBankList.size();
    }



    public BankGridAdapter(Context context, List<BankBean> likesInfos) {
        super();
        this.mContext = context;
        this.mBankList = likesInfos;
    }
    public void setOnBankClickListener(OnBankClickListener listener){
        this.mListener=listener;
    }
    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.credit_bank_item, null);
            holder = new ViewHolder();
            holder.image = (RadiusImageView) convertView
                    .findViewById(R.id.bank_image);
            holder.name = (TextView) convertView
                    .findViewById(R.id.bank_name);
            holder.mainLay=(LinearLayout) convertView
                    .findViewById(R.id.main_lay);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mainLay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    mListener.onClick(mBankList.get(position));
                }
            }
        });
        if (mBankList.get(position).getBank_name()!=null)
        holder.name.setText(mBankList.get(position).getBank_name());
        GlideUtil.getInstance().load(mContext, mBankList.get(position).getBank_url(), holder.image,true);
//        GlideUtil.getInstance().load(mContext, mBankList.get(position).getImg_url(), holder.image, true, false);

        return convertView;
    }

    static class ViewHolder {
        RadiusImageView image;
        TextView name;
        LinearLayout mainLay;
    }

    public interface OnBankClickListener{
        void onClick(BankBean bean);
    }
}
